package cn.itsource.blog.service.impl;

import cn.itsource.blog.domain.Article;
import cn.itsource.blog.mapper.ArticleMapper;
import cn.itsource.blog.service.IArticleService;
import cn.itsource.query.BaseQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {

    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public PageInfo<Article> pageInfo(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getCurrentPage(), baseQuery.getPageSize());
        List<Article> all = articleMapper.getAllByQuery(baseQuery);
        return new PageInfo<>(all);
    }

    @Override
    public void save(Article user) {
        if (user.getId() == null) {
            articleMapper.save(user);
        }else{
            user.setUpdateTime(new Date());
            articleMapper.update(user);
        }
    }

    @Override
    public void delete(Long id) {
        articleMapper.delete(id);
    }

    @Override
    public void batchDelete(List<Article> users) {
        articleMapper.batchDelete(users);
    }



}
